package com.ecr.hub.database.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.ecr.hub.model.destination.Destination;
import com.ecr.hub.model.destination.DestinationRailTranscoder;

public class MapperDestination {

	protected static ParameterizedRowMapper<Destination> mapperDestination = new ParameterizedRowMapper<Destination>() {
		public Destination mapRow(ResultSet rs, int rowNum) throws SQLException {
			Destination dest = new Destination();
			dest.setId(rs.getInt("id"));
			dest.setExtId(rs.getString("ext_id"));
			dest.setHexColor(rs.getString("hex_color"));
			dest.setCreationDate(rs.getDate("creation_date"));
			dest.setLabel(rs.getString("label"));
			dest.setComment(rs.getString("comment"));
			dest.setActive(rs.getBoolean("active"));
			dest.setLstExtId(rs.getString("list_ext_id"));
			return dest;
		}
	};

	/*
	 * Légère entorse au modele mais il fallait le placer soit dans rail, soit
	 * dans destination, soit dans hub...
	 */
	protected static ParameterizedRowMapper<DestinationRailTranscoder> mapperTranscoder = new ParameterizedRowMapper<DestinationRailTranscoder>() {
		public DestinationRailTranscoder mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			DestinationRailTranscoder transcoder = new DestinationRailTranscoder();
			transcoder.setDestinationExtId(rs.getString("ext_id"));
			transcoder.setDestinationId(rs.getInt("destination_id"));
			transcoder.setLstDestinationsExtId(rs.getString("list_ext_id"));
			transcoder.setRailId(rs.getInt("rail_id"));
			return transcoder;
		}
	};
}
